﻿
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[fd_Expediente_Update]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[fd_Expediente_Update]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE PROCEDURE fd_Expediente_Update
(
	@expediente	TEXT
)
AS


BEGIN

	BEGIN TRY
	
		DECLARE @XMLData XML
		
		SET @XMLData = CONVERT(XML, @expediente)
		
		Update Expedientes set
			 ModifyDate = getdate(),
			 ModifiedBy = (SELECT	   a.b.value('ModifiedBy[1]','varchar(50)') AS ModifiedBy FROM @XMLData.nodes('Expediente') a(b)),
			 Descripcion = (SELECT	   a.b.value('Descripcion[1]','varchar(250)') AS Descripcion FROM @XMLData.nodes('Expediente') a(b))
		from Expedientes where id = (SELECT a.b.value('id[1]','int') AS id FROM @XMLData.nodes('Expediente') a(b))
		
	END TRY
   	
   	BEGIN CATCH
   		DECLARE 	@ErrorNumber	INT,
					@ErrorSeverity	INT,
					@ErrorState		INT,
					@ErrorProcedure NVARCHAR(126),
					@ErrorLine		INT,
					@ErrorMessage	NVARCHAR(4000)
				
   		SELECT		@ErrorNumber = ERROR_NUMBER(),
					@ErrorSeverity = ERROR_SEVERITY(),
					@ErrorState = ERROR_STATE(),
					@ErrorProcedure = ERROR_PROCEDURE(),
					@ErrorLine = ERROR_LINE(),
					@ErrorMessage = ERROR_MESSAGE()
				
   		RAISERROR (@ErrorMessage, @ErrorSeverity, @ErrorState)
   	END CATCH

END


